<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="选择一个营销活动" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-search-select-tag
                placeholder="请选择营销活动"
                v-model="marketingId"
                :dictOptions="selectList">
              </j-search-select-tag>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'QyCommodityMarketingForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        commodityId:'',
        url:{
          findMarketingList:"/qy/qyMarketing/findMarketingList",
          edit:"/qy/qyCommodityMarketing/edit"
        },
        marketList:[],
        marketingId:undefined,
        selectList:[]
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {

    },
    methods: {
      submitForm () {
        const that = this;
        that.$emit("changeLoading",true);
        httpAction(this.url.edit,{commodityId:this.commodityId,marketingId:this.marketingId},"put").then((res)=>{
          if(res.success){
            that.$message.success(res.message);
            that.$emit("changeNext",this.commodityId);
          }else{
            that.$message.warning(res.message);
          }
          that.$emit("changeLoading",false);
        }).finally(() => {
          that.confirmLoading = false;
        })
      },
      getDetail(commodityId){
        let params = {id:commodityId};
        var that =this;
        getAction(this.url.findMarketingList,params).then((res)=>{
          if(res.success){
            that.marketList = res.result.marketList;
            if(that.marketList){
              for(var k in that.marketList){
                that.selectList.push({
                  text:that.marketList[k].activityName,
                  value:that.marketList[k].id
                });
              }
            }
            if(res.result.commodityMarketing){
              that.marketingId = res.result.commodityMarketing.marketingId;
            }

          }
        });
        that.commodityId = commodityId;
      }
    }
  }
</script>